<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>修改学生</title>
<link href="../css/bootstrap-cerulean.css" rel="stylesheet">
<link href="../css/charisma-app.css" rel="stylesheet">
<style type="text/css">
body {
	padding-bottom: 40px;
}

.sidebar-nav {
	padding: 9px 0;
}
</style>
	<script src="http://lib.sinaapp.com/js/jquery/2.2.4/jquery-2.2.4.min.js"></script>
	<script src="../js/common/public.js"></script>
	<script src="../js/base64.js"></script>
	<script src="../js/bootstrap-modal.js"></script>
	<script type="text/javascript">
        $(document).ready(function () {
            var urlMsg = parseUrl(window.location.search);
            $("#token").val(urlMsg.token);
            if (urlMsg.token != null) {
                var token = decode(urlMsg.token);
                token=token.substring(0,token.length-1);
            }
            var html = $.ajax({
                type: "GET",
                url: "http://localhost:1068/admin/student/findStudentByStudentNumber?token="+token+"&studentNumber="+urlMsg.studentNumber,
                async: false
            }).responseText;
            var result = eval('(' + html + ')');
            if (result.code != 200) {
                alert(result.msg)
            } else {
                $("#studentNumber").val(result.data.studentNumber);
                $("#name").val(result.data.name);
                $("#duty").val(result.data.duty);
            }

            var classNumber = $.ajax({
                type: "GET",
                url: "http://localhost:1068/admin/class/findAllClass?token="+token,
                async: false
            }).responseText;
            var classNumber = eval('(' + classNumber + ')');
            if (classNumber.code != 200) {
                alert(classNumber.msg)
            } else {
                if (classNumber.data!=null){
                    for (index in classNumber.data){
                        $("#classNumber").append("<option value='"+classNumber.data[index].classNumber+"'>"+classNumber.data[index].className+"</option>");
                    }
                }

            }
        });
        
        function updateStudent() {
            var urlMsg = parseUrl(window.location.search);
            $("#token").val(urlMsg.token);
            if (urlMsg.token != null) {
                var token = decode(urlMsg.token);
                token=token.substring(0,token.length-1);
            }
            var studentNumber = $("#studentNumber").val();
           var name =  $("#name").val();
            var duty = $("#duty").val();
            var classNumber =$("#classNumber").val();
            var html = $.ajax({
                type: "PUT",
                url: "http://localhost:1068/admin/student/updateStudent",
				data:{token:token,studentNumber:studentNumber,name:name,duty:duty,classNumber:classNumber},
                async: false
            }).responseText;
            var result = eval('(' + html + ')');
            if (result.code != 200) {
                alert(result.msg)
            } else {
				alert("更新学生信息成功！")
				window.location.href=document.referrer;
            }
        }
	</script>
</head>

<body>
	<div class="container-fluid"
		style="padding-left:0px;padding-right:2px;">
		<div class="row-fluid">
			<div id="content" class="span10" style="width:100%;">
				<div class="row-fluid sortable">
					<div class="box span12">
						<div class="box-header well">
							<h2>
								<i class="icon-edit"></i>修改学生信息
							</h2>
						</div>
						<div class="box-content" style="text-align:center; padding-top:50px">
							<form action="#" method="post">
							<fieldset>
								<h1>修改学生信息</h1>
								<br><br>
							  <div class="control-group">
								<div class="controls">
								  <span style="font-size:14px">学生学号：</span><input name="studentnumber" value="" class="input" id="studentNumber" type="text" style="height:30px;">
								</div>
							  </div>
							  <br>
							  <div class="control-group">
								<div class="controls">
								  <span style="font-size:14px">学生姓名：</span><input name="name" value="" class="input" id="name" type="text" style="height:30px;">
								</div>
							  </div>
							  <br>
							  <br>
							  <div class="control-group">
								<div class="controls">
								  <span style="font-size:14px">学生职务：</span><input name="duty" id="duty" value="" class="input" id="focusedInput" type="text" style="height:30px;">
								</div>
							  </div>
							  <br>
							  <div class="control-group">
								<div class="controls">
								  <span style="font-size:14px">学生班级：</span>
								  <select name="classnumber" id="classNumber"  style="width:210px;">

								  </select>
								</div>
							  </div>
							  
							  <div class="form-actions">
								<button type="button" id="updateStudentInfo" onclick="updateStudent()" class="btn btn-primary" style="width:100px;">提交</button>
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<button class="btn"  onclick="javascript:history.go(-1);" type="reset" style="width:100px;">取消</button>
							  </div>
							</fieldset>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>